package com.miracle.basemvp.network.download;

import com.miracle.basemvp.network.response.ProgressResponseBody;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * com.miracle.basemvp.network.download
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/9 18:46
 * @see com.miracle.basemvp.network.download
 */
public class DownloadInterceptor implements Interceptor {
    private ProgressDownloadListener downloadListener;

    public DownloadInterceptor(ProgressDownloadListener downloadListener) {
        this.downloadListener = downloadListener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response response = chain.proceed(chain.request());
        return response.newBuilder().body(
                new ProgressResponseBody(response.body(), downloadListener)).build();
    }
}
